<template>
  <a-modal title="选择司机" :visible="visible" @ok="visible = false" @cancel="visible = false" :width="1200">
    <div class="table-page-search-box">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :md="8" :sm="24">
            <a-form-item label="用户名称">
              <a-input placeholder="请输入用户名称" v-model="queryParam.name" allowClear></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item label="手机号码">
              <a-input placeholder="请输入手机号码" v-model="queryParam.tel" allowClear></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item label="车牌号">
              <div class="flex">
                <a-input class="inp" placeholder="请输入车牌号码" v-model="queryParam.car_no" allowClear></a-input>
                <a-button type="primary" @click="getList()">查询</a-button>
              </div>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <a-card :border="false">
      <a-table
        size="default"
        :columns="columns"
        :data-source="list"
        :row-key="(record) => record.id"
        :pagination="{
          total: this.total,
          pageSize: this.pageSize,
          showSizeChanger: false,
          onChange: this.tablePageChange,
        }"
        :scroll="{ x: 'max-content' }"
      >
        <span slot="content" slot-scope="text, record">
          <div class="content" v-if="record.saas_user">
            <div class="img">
              <a-avatar shape="square" :size="48" icon="user" :src="record.saas_user.avatar" />
            </div>

            <div class="txt">
              <h3>{{ record.saas_user.name }}</h3>
              <p>{{ record.saas_user.mobile }}</p>
            </div>
          </div>
        </span>

        <span slot="status" slot-scope="text, record">
          <a-badge :color="getStatus(record.status)[1]" :text="getStatus(record.status)[0]" />
        </span>

        <span slot="action" slot-scope="text, record">
          <a-button type="link" size="small" @click="$emit('handle', 'select', record)">选择</a-button>
        </span>
      </a-table>
    </a-card>
  </a-modal>
</template>
<script>
import { districtList } from '@/api/driver'

const columns = [
  {
    title: 'ID',
    dataIndex: 'id',
    width: 100,
  },
  {
    title: '用户信息',
    scopedSlots: {
      customRender: 'content',
    },
    width: 200,
  },
  {
    title: '线路名称',
    dataIndex: 'line_name',
  },
  {
    title: '真实姓名',
    dataIndex: 'name',
  },
  {
    title: '车牌号',
    dataIndex: 'car_no',
  },
  {
    title: '司机状态',
    scopedSlots: {
      customRender: 'status',
    },
  },
  {
    title: '操作',
    scopedSlots: {
      customRender: 'action',
    },
  },
]
export default {
  components: {},

  data() {
    return {
      total: 0,
      pageNo: 1,
      pageSize: 10,
      columns,

      queryParam: {
        name: '',
        mobile: '',
        status: '1',
        car_no: '',
      },
      list: [],
      visible: false,
    }
  },

  mounted() {
    this.getList()
  },

  computed: {
    getStatus() {
      return (status) => {
        let text, color
        switch (status) {
          case '0':
            text = '未开启'
            color = 'rgba(0, 0, 0, 0.25)'
            break

          case '1':
            text = '已开启'
            color = '#65C817'
            break
        }
        return [text, color]
      }
    },
  },

  methods: {
    edit(item) {},

    // 获取数据列表
    async getList(pageNo = 1) {
      const hide = this.$message.loading('加载中', 0)
      let { queryParam, pageSize } = this

      const res = await districtList({
        ...queryParam,
        pageSize,
        pageNo,
      })
      if (res.code == 0) {
        console.log('res,', res)
        this.selectedRowKeys = []
        let { totalCount, list } = res.data
        this.total = totalCount
        this.list = list
      }
      hide()
    },

    // 分页请求
    tablePageChange(e) {
      this.getList(e)
    },
  },
}
</script>

<style lang="less" scoped>
.searchBox {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  padding: 8px 0 18px 0;
  /deep/ .ant-input-affix-wrapper {
    width: 220px;
    margin-right: 20px;
  }
  .select {
    display: flex;
    align-items: center;
    margin-right: 20px;
  }
}

.content {
  display: flex;
  align-items: center;
  height: 48px;
  max-width: 300px;
  overflow: hidden;

  .txt {
    margin-left: 16px;
    flex: 1;
    overflow: hidden;

    * {
      margin: 0;
      font-size: 14px;
      text-overflow: ellipsis;
      white-space: nowrap;
      overflow: hidden;
    }

    h3 {
      color: rgba(0, 0, 0, 0.85);
    }

    p {
      color: rgba(0, 0, 0, 0.45);
    }
  }
}

.flex {
  display: flex;

  .inp {
    margin-right: 20px;
  }
}
</style>
